package com.cysyz.web.action;

import javax.annotation.Resource;

import com.cysyz.commonservice.mycommonservice.login.LoginService;
import com.cysyz.commonservice.mycommonservice.support.Loginable;
import com.cysyz.web.form.LoginForm;

@Controller("/login")
public class LoginAction extends Action {
	@Resource private LoginService loginService;
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String forwardName = "failure";
		LoginForm loginForm = (LoginForm) form;
		User userInput  = new User();
		userInput.setId(loginForm.getId());
		userInput.setPassword(loginForm.getPassword());
		Loginable user = loginService.login(userInput);
		if (user != null) {
			request.getSession().setAttribute("user", user);
			forwardName = "success";
		}
		return mapping.findForward(forwardName);
	}
}
